﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace FileToVideo.Helpers
{
    /// <summary>
    /// 日志打印
    /// </summary>
    public class Logger
    {
        /// <summary>
        /// 用MessabeBox显示日志
        /// </summary>
        /// <param name="format"></param>
        /// <param name="file"></param>
        /// <param name="member"></param>
        /// <param name="line"></param>
        /// <param name="text"></param>
        public void MessageBoxShow(string format,string file = null, string member = null, int line = -1, object text = null)
        {
            MessageBox.Show(string.Format(format, file, member, line, text.ToString()), file, MessageBoxButton.OK, MessageBoxImage.Information);
        }

#if DEBUG
        /// <summary>
        /// 打印日志
        /// </summary>
        /// <param name="text"></param>
        /// <param name="file"></param>
        /// <param name="member"></param>
        /// <param name="line"></param>
        public void Log(string text,
                [CallerFilePath] string file = "",
                [CallerMemberName] string member = "",
                [CallerLineNumber] int line = 0)
        {
            MessageBoxShow("{0}({1})[{2}]: {3}", Path.GetFileName(file), member, line, text);
        }

        /// <summary>
        /// 打印日志
        /// </summary>
        /// <param name="text"></param>
        /// <param name="file"></param>
        /// <param name="member"></param>
        /// <param name="line"></param>
        public void Log(object text,
                [CallerFilePath] string file = "",
                [CallerMemberName] string member = "",
                [CallerLineNumber] int line = 0)
        {
            MessageBoxShow("{0}({1})[{2}]: {3}", Path.GetFileName(file), member, line, text);
        }        
#else
        /// <summary>
        /// 打印日志
        /// </summary>
        /// <param name="text"></param>
        /// <param name="file"></param>
        /// <param name="member"></param>
        /// <param name="line"></param>
        public void Log(string text,
                string file = "",
                string member = "",
                int line = 0)
        {
            Console.WriteLine(text);
        }

        /// <summary>
        /// 打印日志
        /// </summary>
        /// <param name="text"></param>
        /// <param name="file"></param>
        /// <param name="member"></param>
        /// <param name="line"></param>
        public void Log(object text,
                string file = "",
                string member = "",
                int line = 0)
        {
            Console.WriteLine(text);
        }
#endif
    }
}
